﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using WorldView;
using LightEffects;

namespace DrawableObjects
{
    /// <summary>
    /// Abstract superclass containing all common methods and attributes of 
    /// drawable objects.
    /// </summary>
    public abstract class DrawableObject 
    {
        public abstract void Update();

        public Matrix worldMatrix
        {
            get;
            protected set;
        }

        /// <summary>
        /// Gets the 2D Position of the object in the world
        /// </summary>
        public virtual Vector2 getGamePosition()
        {          
            Vector3 trans = worldMatrix.Translation;
            Vector2 gamePosition = new Vector2(trans.X, trans.Z);

            return gamePosition;
        }

        public void setPosition(Vector2 gamePosition)
        {
            Vector3 scale;
            Vector3 trans;
            Quaternion rota;
            worldMatrix.Decompose(out scale, out rota, out trans);
            trans.X = gamePosition.X;
            trans.Z = gamePosition.Y;
            worldMatrix = Matrix.CreateScale(scale) * Matrix.CreateFromQuaternion(rota) * Matrix.CreateTranslation(trans);
        }

        protected DrawableObject(Matrix worldMatrix)
        {
            this.worldMatrix = worldMatrix;
        }

        //used by specialeffects
        protected DrawableObject()
        {
        }

    }
}

